package com.example.lcpractice.thread;

import java.util.concurrent.TimeUnit;
class MyDate1 {
    //共享变量 1.1 不加volatile关键字没有可见性，加了后主线程可见性
    public int x = 100;

    public void changeX() {
        this.x = 60;
    }

    public void add() {
        x++;
    }
}
public class ThreadDirtyRead {


    public static void main(String[] args) {
        MyDate1 myDate = new MyDate1();
        Thread threadA = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t 开始");

            myDate.changeX();

            System.out.println(Thread.currentThread().getName() + "结束时\t number value=" + myDate.x);
            Thread.currentThread().interrupt();
        }, "A线程");
        Thread threadB = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t 开始");

            System.out.println(Thread.currentThread().getName() + "结束时\t update number value=" + myDate.x);

        }, "B线程");

        threadA.start();
        threadB.start();
        System.out.println("最终线程："+Thread.currentThread().getName() + "\t over number value=" + myDate.x);
    }

}
